import { defineStore } from 'pinia'

export const useOrderStore = defineStore('order', {
  persist: true,
  state: () => ({
    order_no: '',
    state: 0,
    requirement_text: '',
    service: {
      member_id: 0,
      quotation: {
        scene: "",
        remarks: "",
        people_price: "",
        material_price: "",
        base_people_price: ""
      },
      scene_image: [],
      service_date: "",
      service_time: "",
      customer_sign: "",
      product_image: "",
      product_sn_image: ""
    },
    customer: {
      name: '',
      mobile: '',
      address: '',
      city: '',
      state: '',
      zip_code: '',
      service_date: '',
      service_time: '',
      service_category_name: '',
      service_name: '',
      install_position: '',
      service_category_id: 0,
      service_id: 0,
      additional_requirements: [] as string[],
      remarks: '',
      install_position_image: [] as string[],
      wall_category: '',
      master_images: [] as string[],
      electricity_meter_images: [] as string[],
      environment_images: [] as string[],
      video: ''
    }
  }),
  actions: {
    reset() {
      this.$reset()
    },
    fillFromOrderDetail(order: any) {
      console.log('订单信息order', order)
      this.order_no = order.order_no || ''
      this.state = order.state || 0
      this.requirement_text = order.requirement_text || ''
      if (order.service) {
        Object.assign(this.service, {
          member_id: order.service.member_id || 0,
          quotation: {
            scene: order.service.quotation.scene || "",
            remarks: order.service.quotation.remarks || "",
            people_price: order.service.quotation.people_price || "",
            material_price: order.service.quotation.material_price || "",
            base_people_price: order.service.quotation.base_people_price || ""
          },
          scene_image: order.service.scene_image || [],
          service_date: order.service.service_date || '',
          service_time: order.service.service_time || '',
          customer_sign: order.service.customer_sign || '',
          product_image: order.service.product_image || '',
          product_sn_image: order.service.product_sn_image || ''
        })
      }
      if (order.customer) {
        Object.assign(this.customer, {
          name: order.customer.name || '',
          mobile: order.customer.mobile || '',
          address: order.customer.address || '',
          city: order.customer.city || '',
          state: order.customer.state || '',
          zip_code: order.customer.zip_code || '',
          service_category_name: order.customer.service_category_name || '',
          service_name: order.customer.service_name || '',
          service_date: order.customer.service_date || '',
          service_time: order.customer.service_time || '',
          install_position: order.customer.install_position || '',
          service_category_id: order.customer.service_category_id || null,
          service_id: order.customer.service_id || null,
          additional_requirements: order.customer.additional_requirements || [],
          remarks: order.customer.remarks || '',
          install_position_image: order.customer.install_position_image || [],
          wall_category: order.customer.wall_category || '',
          master_images: order.customer.master_images || [],
          electricity_meter_images: order.customer.electricity_meter_images || [],
          environment_images: order.customer.environment_images || [],
          video: order.customer.video || '',

        })
      }
    }
  }
}) 